package com.dbexplore.db;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;


public class DBHelper {
    public static void cleanup(Statement stmt) {
        try {
            if (stmt != null)
                stmt.close();
        } catch (SQLException exc) {
            exc.printStackTrace();
        }

    }

    public static void HandleDBException(SQLException e) throws SQLException {
        System.out.println("Database Error Message " + e.getMessage());
        throw e;
    }

    private static PreparedStatement prepare(String sqlString) throws SQLException {
        return DB.INSTANCE.connection.prepareStatement(sqlString);
    }

    public static ResultSet execute(String sqlString) throws SQLException {
        PreparedStatement preparedStatement = prepare(sqlString);
        ResultSet resultSet = preparedStatement.executeQuery();
        return resultSet;
    }
}
